/**
 * Created by wxb on 2016/10/20.
 */
'use strict';

angular.module('BlurAdmin')
  .factory('loginUrl', function (publicFunc) {
    var prefix = '/kt/admin/';
    var url = {
      login: {
        url: 'user/login',
        method: 'POST'
      },
      logout: {
        url: 'user/logout',
        method: 'DELETE'
      }

    };
    return publicFunc.urlAddPrefix(url, prefix);
  })
  .service('loginService', function (httpService, loginUrl, localStorageService) {
    this.login = function (postData) {
      return httpService.http(postData, loginUrl.login, {})
    };
    this.logout = function () {
      return httpService.http({}, loginUrl.logout, {});
    };

    this.initUser = function () {
      if(!localStorageService.cookie.get('user')){
        localStorageService.cookie.set('user', {anonymous: true});
      }
      if(localStorageService.cookie.get('user') && (new Date().getDate() - localStorageService.cookie.get('user').lastLoginTime ) > 7) {
        localStorageService.cookie.set('user', {anonymous: true});
      }
    };





  });
